import time
from selenium import webdriver
from selenium.webdriver.common.by import By
dr = webdriver.Chrome()
dr.get("https://www.hbjcxy.com/")
# 最大化
dr.maximize_window()
# 停留3s
time.sleep(3)
# 找到按钮
btn = dr.find_element(By.XPATH,"/html/body/div[2]/div[1]/div[1]/div[1]/div/div/a")
# 点击按钮
btn.click()
time.sleep(3)
print(dr.title)
# 获取所有打开界面的id 每当新打开一个界面 就会将对应的id放到数组里 放到最后一个位置
handles = dr.window_handles
# 跳转到最新的标签
dr.switch_to.window(handles[-1])
print(dr.title)
items = dr.find_elements(By.CSS_SELECTOR,".list-item")
for item in items:
    title = item.find_element(By.CSS_SELECTOR,".list-title").text.strip()
    date = item.find_element(By.CSS_SELECTOR,".list-meta").text.strip()
    print(title)
    print(date)
# 找到下一页
dr.find_element(By.XPATH,"/html/body/div[1]/div[2]/div[12]/table/tbody/tr/td/a[12]").click()
# 转跳界面
handles = dr.window_handles
# 跳转到最新的标签
dr.switch_to.window(handles[-1])
items = dr.find_elements(By.CSS_SELECTOR,".list-item")
for item in items:
    title = item.find_element(By.CSS_SELECTOR,".list-title").text.strip()
    date = item.find_element(By.CSS_SELECTOR,".list-meta").text.strip()
    print(title)
    print(date)